package com.ztq.test.login.dao;

import java.sql.SQLException;

import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;

import com.ztq.test.login.entity.T_userInfo;

/**
 * @author: ztq
 * @date: 2016-1-8 下午03:38:44
 * @description: 用于用户登录注册的类，实现LoginDao接口
 * @version:1.0
 */
public class LoginDaoIMPL extends SqlMapClientDaoSupport implements LoginDao {
	// 查询state为1（正常状态）的用户名所对应的记录
	public T_userInfo queryUsernameRecord(T_userInfo userInfo) {
		T_userInfo result = null;
		try {
			result = (T_userInfo) getSqlMapClient().queryForObject(
					"USERLOGIN.queryUsernameRecord", userInfo);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return result;
	}

	//查询state为1的邮箱email对应的记录
	public T_userInfo queryEmailRecord(T_userInfo userInfo) {
		T_userInfo result = null;
		try {
			result = (T_userInfo) getSqlMapClient().queryForObject(
					"USERLOGIN.queryEmailRecord", userInfo);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return result;
	}

	// 用户信息插入（即注册的过程）
	public boolean insert(T_userInfo userInfo) {
		boolean isSuccess = true;
		try {
			getSqlMapClientTemplate().insert(
					"USERLOGIN.insertUserInfo", userInfo);
		} catch (Exception e) {
			isSuccess = false;
			e.printStackTrace();
		}
		return isSuccess;
	}
	
	//查询用户名、密码符合的记录
	public T_userInfo queryPasswordRecord(T_userInfo userInfo){
		T_userInfo result = null;
		try {
			result = (T_userInfo) getSqlMapClient().queryForObject(
					"USERLOGIN.queryPasswordRecord", userInfo);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return result;
	}

	// 查询用户信息是否存在（即登录的过程）
	public T_userInfo queryUserInfo(T_userInfo userInfo) {
		return null;
	}
	
	//查询用户的id
	public String queryUserId(T_userInfo userInfo){
		String result = null;
		try {
			result = (String) getSqlMapClient().queryForObject(
					"USERLOGIN.queryUserId", userInfo);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return result;
	}
}